package com.linpq.road.controller;

import java.util.List;

import com.linpq.road.mapper.RdImportLogMapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.linpq.common.annotation.Log;
import com.linpq.common.enums.BusinessType;
import com.linpq.road.domain.RdImportLog;
import com.linpq.road.service.RdImportLogService;
import com.linpq.common.core.controller.BaseController;
import com.linpq.common.core.domain.AjaxResult;
import com.linpq.common.utils.poi.ExcelUtil;
import com.linpq.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 *
 * @author linpq
 * @date 2021-08-13
 */
@Controller
@RequestMapping("/road/log")
public class RdImportLogController extends BaseController {
    private String prefix = "road/log";

    @Autowired
    private RdImportLogService rdImportLogService;
    @Autowired
    private RdImportLogMapper rdImportLogMapper;

    @RequiresPermissions("road:log:view")
    @GetMapping()
    public String log() {
        return prefix + "/log";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("road:log:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RdImportLog rdImportLog) {
        startPage();
        List<RdImportLog> list = rdImportLogService.selectRdImportLogList(rdImportLog);
        return getDataTable(list);
    }
    @RequestMapping(value = "/listToSectionName",method = RequestMethod.POST)
    @ResponseBody
    public TableDataInfo list(){
        startPage();
        List<RdImportLog> rdImportLogs = rdImportLogMapper.selectRdImportLogByRoadSectionId();
        return getDataTable(rdImportLogs);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("road:log:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RdImportLog rdImportLog) {
        List<RdImportLog> list = rdImportLogService.selectRdImportLogList(rdImportLog);
        ExcelUtil<RdImportLog> util = new ExcelUtil<RdImportLog>(RdImportLog. class);
        return util.exportExcel(list, "log");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("road:log:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RdImportLog rdImportLog) {
        return toAjax(rdImportLogService.insertRdImportLog(rdImportLog));
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        RdImportLog rdImportLog =rdImportLogService.selectRdImportLogById(id);
        mmap.put("rdImportLog", rdImportLog);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("road:log:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RdImportLog rdImportLog) {
        return toAjax(rdImportLogService.updateRdImportLog(rdImportLog));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("road:log:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(rdImportLogService.deleteRdImportLogByIds(ids));
    }
}
